using System;
using LeagueOfRila.Controller;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Data;
using System.Collections.Generic;
using LeagueOfRila.Callback;
using LeagueOfRila.Model;

namespace LeagueOfRila
{
#if WINDOWS || XBOX
    public static class Client
    {
        public static Player player;
        public static Song backgroundSong; 
        public static List<Song> mapSongsList = new List<Song>();
        public static int playingSong = -1;

        //sons menu
        public static SoundEffect keysound;
        public static SoundEffect entersound;

        //sons personnages
        public static SoundEffect warReady;
        public static SoundEffect priestReady;
        public static SoundEffect rogueReady;
        public static SoundEffect mageReady;

        //musiques
        public static SoundEffectInstance musicInstance;
        public static Thread threadMusic;
        public static bool musicLance = false;


        static void Main(string[] args)
        {
            GotoNextStep("MenuConnection");
        }

        /**
         * Met fin au step en cour et passe au step suivant 
         * Exemple : Met fin a MenuConnection et lance le menu de 
         *           choix de personnages 
         */
        public static void GotoNextStep(String step)
        {
            switch (step)
            {
                case "MenuConnection" :
                    
                    Thread threadMenuConnection = new Thread(() => {
                        MenuConnectionController MenuConnection = new MenuConnectionController();
                        MenuConnection.Run();
                    });
                    threadMenuConnection.Start();
                    break;

                case "MenuCharacterChoice":
                    
                    Thread threadMenuCharac = new Thread(() => { 
                        MenuCharacterChoiceController menuCharac = new MenuCharacterChoiceController();
                        menuCharac.Run();
                    });
                    threadMenuCharac.Start();
                    // Tue l'ancien processus
                    Thread.CurrentThread.Abort();
                    break;

                case "Game":

                    Thread threadGame = new Thread(() => { 
                        GameController game = new GameController(); 
                        game.Run(); 
                    });
                    threadGame.Start();
                    // Tue l'ancien processus
                    Thread.CurrentThread.Abort();
                    break;
            }
      
        }

        public static void PlayMusic(Song song, bool repeat)
        {
            threadMusic = new Thread(() =>
            {
                musicLance = true;
                MediaPlayer.IsRepeating = repeat;
                MediaPlayer.Play(song);
            });
            threadMusic.Start();
        }

        public static void PlaySound(SoundEffect son)
        {
            Thread threadSound = new Thread(() =>
            {
                son.Play();
 
            });
            threadSound.Start();
        }

        public static void StopMusic()
        {
            threadMusic.Abort();
            musicLance = false;
        }
    }
#endif
}

